// pages/live/live.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    liveId: '',
    playF: '',
    playR: '',
    userId: '',
    liveurl: '',
    videoContext: {}
  },
  backto: function () {
    console.log('返回')
  }
  ,
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('=====live  onLoad start ====================');
    console.log(options);
    console.log(typeof options);
    console.log('=====onLoad end =============');
    if (options != null && options.playF != null) {
      console.log(options.playF);
      var playF = options.playF.replace("FLVAUTHKEY", "?");
      console.log(playF);
      this.setData({
        userId: -1
      })
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

    var self = this;

    this.data.videoContext = wx.createLivePlayerContext(app.globalData.currentlive.liveId);
    console.log(this.data.videoContext)
    if (this.data.playF == '') {
      console.log('ready设置播放配置！！！！');
      this.setData({
        liveId: app.globalData.currentlive.liveId,
        playF: app.globalData.currentlive.playF,
        userId: app.globalData.userId
      })
    }

    //默认进入直播全屏
    if (!this.data.fullScreen) {
      this.data.videoContext.requestFullScreen({
        // direction: 90,
      })
    } else { }

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.setKeepScreenOn({
      keepScreenOn: true,
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    var that = this;
    console.log("==========onShareAppMessage===============")
    console.log(this.data.playF);
    console.log(this.data.userId);
    console.log(this.data.liveId);
    var playF = this.data.playF;
    playF = playF.replace("?", "FLVAUTHKEY");
    console.log('playf=' + playF);
    console.log(res);
    return {
      title: '分享课堂',
      path: '/pages/live/live?userId=-1&liveId=' + this.data.liveId + '&playF=' + playF,
      success: function (res) {
        console.log(res);
      }
    }
  },
  /**
   *  获取答题 
   */
  getanswer: function () {
    wx.navigateTo({
      url: '/pages/page/answer/answer',
    })
  }
  ,
  onFullScreenChange: function (e) {
    this.setData({
      fullScreen: e.detail.fullScreen
    })
    console.log(e);
    wx.showToast({
      title: this.data.fullScreen ? '全屏' : '退出全屏',
    })
  },

})